package kordegi.forumsystem.controller;

import io.jsonwebtoken.lang.Assert;
import kordegi.forumsystem.common.lang.Result;
import kordegi.forumsystem.service.SortingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author kordegi
 * @date 2022.05.02 13:00
 * @Description
 */

@RestController
public class SortingController {
    @Autowired
    SortingService sortingService;

    public Result SortingUser(@Validated @RequestBody String username) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", "200");
        map.put("CommentList", sortingService.sortUsers(username));
        Assert.notNull(map);

        return Result.succ(map);
    }

    public Result SortingArticle(@Validated @RequestBody String title) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", "200");
        map.put("CommentList", sortingService.sortArticles(title));
        Assert.notNull(map);

        return Result.succ(map);
    }
}
